package edu.hitsz.shoot;

import edu.hitsz.aircraft.AbstractAircraft;
import edu.hitsz.aircraft.EnemyAircraft;
import edu.hitsz.bullet.BaseBullet;
import edu.hitsz.bullet.EnemyBullet;
import edu.hitsz.bullet.HeroBullet;

import java.util.LinkedList;
import java.util.List;

public class ShootScatter implements Shoot{
    @Override
    public List<BaseBullet> doShoot(AbstractAircraft aircraft) {
        int shootNum = 3;
        int direction;
        if (aircraft instanceof EnemyAircraft) {
            direction = 1;
        } else {
            direction = -1;
        }
        int power = aircraft.getPower();
        List<BaseBullet> res = new LinkedList<>();
        int x = aircraft.getLocationX();
        int y = aircraft.getLocationY() + direction * 2;
        int speedX = 0;
        int speedY = aircraft.getSpeedY() + direction * 5;
        BaseBullet bullet;
        for (int i = 0; i < shootNum; i++) {
            // 子弹发射位置相对飞机位置向前偏移
            // 多个子弹横向分散
            speedX = (shootNum / 2 - i);
            if (aircraft instanceof EnemyAircraft) {
                bullet = new EnemyBullet(x + (i*2 - shootNum + 1)*2, y, speedX, speedY, power);
            } else{
                bullet = new HeroBullet(x + (i*2 - shootNum + 1)*2, y, speedX, speedY, power);
            }
            res.add(bullet);
        }
        return res;
    }
}
